<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/vue.js"></script>
    <script src="js/jquery.js"></script>

</head>
<body>
<div id="app">
    <form id="formAdd">
        <input type="hidden" name="id" v-model="brand.id">
        名称：<input type="text" name="name" v-model="brand.name">
        编号：<input type="text" name="code" v-model="brand.code">
        <input type="button" value="提交" @click="update()">
    </form>
</div>

<script>
    //获取url上的请求参数
    function getParams() {
        //获取问号及问号后面的内容
        var url = window.location.search;
        var params = new Object();
        if (url.indexOf("?") != -1) {
            //截取问号后面的内容,再使用&分割多个属性
            var arr = url.substr(1).split("&");
            for (var i = 0; i < arr.length; i++) {
                //使用=分割为keyvalue
                var keyValue = arr[i].split("=");
                params[keyValue[0]] = keyValue[1];
            }
        }
        return params;
    }

    var vue = new Vue({
        el: '#app',
        data:{
          brand:{}
        },
        methods: {
            update: function () {
                $.ajax({
                    url:"http://localhost:8080/brand/update",
                    type:'PUT',
                    data:$('#formAdd').serialize(),
                    success:function () {
                        location.href="index.html";
                    }
                })
            }
        },
        mounted:function () {
            let map = getParams();
            _this=this;
            $.get('http://localhost:8080/brand/detail/'+map.id+'', {}, function (data) {
                if(data.code==200){
                    _this.brand=data.data;
                }else {
                    alert(data.msg);
                }
            });
        }
    });



</script>

</body>
</html>